package com.lzq.badminton.controller;

import com.lzq.badminton.entity.Arena;
import com.lzq.badminton.service.ArenaService;
import com.lzq.badminton.service.BookingService;
import com.lzq.badminton.vo.BookingVo;
import com.lzq.badminton.vo.ListBookingsVo;
import com.lzq.badminton.vo.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/booking")
public class BookingController {
    @Autowired
    private BookingService bookingService;

    @Autowired
    private ArenaService arenaService;

    @GetMapping("/listBookings")
    @ApiOperation(value="按照日期和球馆展示预定情况")
    public ResponseResult listBookings(@RequestParam Long arenaId, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate localDate){
        List<BookingVo> bookingVos = bookingService.listBookings(arenaId, localDate);
        Arena arena = arenaService.getById(arenaId);
        Integer courtSize = arena.getCourtSize();
        String timeSlots = arena.getTimeSlots();
        String[] timeSlotArray = timeSlots.split(";");
        ListBookingsVo listBookingsVo = ListBookingsVo.builder().courtSize(courtSize).timeSlotArray(timeSlotArray).bookingVoList(bookingVos).adDate(arena.getAdDate()).build();
        return ResponseResult.okResult(listBookingsVo);
    }

}
